package com.wangchao.administrator.zenmechi.ui.registactivity;

import com.wangchao.administrator.zenmechi.ui.loginactivity.Person;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by cbb on 2016/10/18.
 * Email: 1023151857@qq.com
 */
public class RegistModle implements RegistContract.Modle {
    private String objId;

    @Override
    public void addData(final String name, final String pwd, Subscriber<String> id) {
        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                Person p2 = new Person();
                p2.setName(name);
                p2.setAddress(pwd);
                p2.save(new SaveListener<String>() {
                    @Override
                    public void done(String objectId,BmobException e) {
                        if(e==null){
                            objId=objectId;
                        }else{
                           // Log.e("bomb","注册失败");
                        }
                    }
                });
                subscriber.onNext(objId);
            }
        }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(id);
    }
}
